package com.sunny.ynhz.adapter;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.api.okhttp.OkHttpHelper;
import com.sunny.ynhz.ui.base.AppBaseTitleBarActivity;
import com.sunny.ynhz.utils.FileUtils;

/**
 * Created by huhuan123 on 2018/6/5.
 */

public class TestActivity extends AppBaseTitleBarActivity {
    SparseArray<String> mSparseArray = new SparseArray();
    String tag = "hu";
    private TextView tv_file_time;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_file_progress);
        TextView textView=findViewById(R.id.tv_file_option);
        tv_file_time = findViewById(R.id.tv_file_name);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mSparseArray.get(0) == null) {
                    mSparseArray.put(0, tag);
                    textView.setText("下载中");

                    OkHttpHelper.getDownloadDelegate().downloadBreakConAsyn("http://oss.taiyangos.com/down/gpsbd/GPSBD-v1.4.1.apk", FileUtils.markDownFilePathString(TestActivity.this), new OkHttpHelper.ResultCallback<String>() {
                        @Override
                        public void onResponse(String response) {

                        }

                        @Override
                        public void onProgressUpdate(long bytesRead, long contentLength, boolean done) {
                            super.onProgressUpdate(bytesRead, contentLength, done);
                            int progrss = (int) (((float) bytesRead / 9229509f) * 100);
                            tv_file_time.setText(bytesRead+"------------------");

                        }
                    }, tag);
                } else {
                    textView.setText("暂停");
                    OkHttpHelper.cancelTag(tag);
                    mSparseArray.remove(0);
                }

            }
        });
    }
}
